package com.woniuxy.springbootrabbit.kill;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class KillConsumer {
    // 接收生产者发送的消息
    @RabbitListener(queues = "kill_queue")  // 监听消息队列
    public void accept(String msg, Channel channel, Message message){
        System.out.println("下订单接收到:" + msg);
        // 模拟下单业务消耗的时间
        try {
            Thread.sleep(1000);
            //确认收到消息
            //参数1：消息的id
            //参数2：是否批量确认
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
//qos  预取值